Conditional Statements
If <condition>
<statements>
EndIf
IF
statement will check the <condition> and
if it's true will execute the commands inside the <statements>
block.
Parameters
<condition>
Numeric or string expression.
<statements>
One or
more statements.
Remarks
- Use an If......Else
block to define several blocks of statements, one of which will execute.
If <condition>
<statements>
Else
<statements>
EndIf
- When the If statement evaluates to TRUE, the
statement, or block of statements, following the If statement, is
executed. Then control jumps to the point after the statement, or block
of statements, following the Else statement. When the If statement
evaluates to FALSE, the statement, or block of statements, following
the If statement is skipped and the statement, or block of statements,
following the optional Else statement is executed.
If <condition1>
<statements>
ElseIf <condition2>
<statements>
ElseIf <condition3>
<statements>
Else
<statements>
EndIf
- If...ElseIf is really just a special case of If....Else.
Notice that you can have any number of ElseIf clauses, or none at all. You
can include an Else clause regardless of whether you have ElseIf clauses.
If <condition>
[Then] GoTo <label>
- On true will jump to the label specified by <label>
- ElseIf can also be written as "Else If" or "Elif"
Example
1. IF....THEN:
$choice = accept("voicemenu.wav",1)
if $choice = 0 then goto TERMINATE
2. IF...ELSE...ENDIF:
if $Balance < $MinBalance
; Insufficient Balance in account
play "nobalance.wav"
else
; Your request will be processed within 1 hour
play "requestok.wav"
endif
3. IF...ELSE...ENDIF:
if $Balance < $MinBalance OR ( $AccountType = "CA" AND date.cmp($DueDate,$date) > 0 )
; Your request has been blocked, please contact the administrative department
play "blocked.wav"
else
; Your request will be processed within 1 hour
play "requestok.wav"
endif
4. IF...ELSEIF...ENDIF:
if $account_type = "SA"
; Not applicable for savings account
play "notapplicable_SA.wav"
else if $account_type = "CA"
; You must have a minimum balance of 100000 in your account
play "minbal.wav"
elif $account_type = "NRI"
$sql = format("SELECT * from MASTER where ACCTYPE = 'NRI' AND ACCNO = '%s'",$AccNo)
$alias = db.RunSQL($db,$sql)
if $alias.eof
; Your account details are not found
play "invalid.wav"
endif
endif